package gov.kqqzyyy.monkey.ydhl.ui;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ExpandableListView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import adapter.JYJGListAdapter;
import butterknife.BindView;
import butterknife.ButterKnife;
import gov.kqqzyyy.monkey.ydhl.R;
import mytools.MyBaseActivity;
import mytools.MyServiceUtil;
import objects.LisJYJG;
import objects.LisJYXM;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ReportJYActivity extends MyBaseActivity implements SwipeRefreshLayout.OnRefreshListener {

    @BindView(R.id.jy_swipe_layout)
    SwipeRefreshLayout mJYSwipeRefreshLayout;
    @BindView(R.id.jy_expandable_lv)
    ExpandableListView mJYExpandableListView;

    private List<LisJYXM> mJyxmList;
    private List<LisJYJG> mJyjgList;

    private JYJGListAdapter adapter;

    private Call<String> jyxmCall;
    private Call<String> jyjgCall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report_jy);
        ButterKnife.bind(this);

        mJYSwipeRefreshLayout.setColorSchemeResources(R.color.holo_green_dark, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light);
        mJYSwipeRefreshLayout.setOnRefreshListener(this);
        adapter = new JYJGListAdapter(this);
        mJYExpandableListView.setAdapter(adapter);
    }

    @Override
    public void onRefresh() {

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (jyxmCall != null && jyxmCall.isExecuted()) {
            jyxmCall.cancel();
        }
        if (jyjgCall != null && jyjgCall.isExecuted()) {
            jyjgCall.cancel();
        }

    }

    //获取检验项目
    private void doGetJYXM(String zyhm) {
        jyxmCall = MyServiceUtil.getJYXMCall(zyhm);
        Callback<String> callback = new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                String result = response.body();
                if (result != null) {
                    Gson gson = new Gson();
                    mJyxmList = gson.fromJson(result, new TypeToken<List<LisJYXM>>() {
                    }.getType());
                }

            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        };
        jyxmCall.enqueue(callback);

    }

    //获取检验结果
    private void doGetJYJG(String zyhm) {
        jyjgCall = MyServiceUtil.getJYJGCall(zyhm);
        Callback<String> callback = new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                String result = response.body();
                if (result != null) {
                    Gson gson = new Gson();
                    mJyjgList = gson.fromJson(result, new TypeToken<List<LisJYJG>>() {
                    }.getType());
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        };
        jyjgCall.enqueue(callback);

    }
}
